<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="base/include/head">
</head>
<body>
 	   	<div id="tb" style="padding:5px;">
			编码或名称：<input id="dicCode" class="easyui-textbox" style="height: 21px;width:180px" value="" />
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="dataTable()"> 搜索 </a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-add"    onclick="openDilog()">新增</a> 
			<a href="#" class="easyui-linkbutton" iconCls="icon-help"   onclick="caozuo()">操作指南</a>
		</div>
		<table id="tt"></table> 
		
		<div id="tb_sun" style="padding:5px;">
			<input id="fid" type="hidden" value="" />
			<a href="#" class="easyui-linkbutton" iconCls="icon-add"    onclick="openSunDilog()">新增</a> 
			<a href="#" class="easyui-linkbutton" iconCls="icon-help"   onclick="caozuo()">操作指南</a>
		</div>
		<table id="tt_sun"></table> 
	<!--模块菜单项 -->
	<div id="mm" class="easyui-menu" style="width: 120px;">
		<div data-options="iconCls:'icon-edit',name:'update'">修改</div>
		<div data-options="iconCls:'icon-remove',name:'remove'" >移除</div>
		<div data-options="iconCls:'icon-reload',name:'status'" >变更状态</div>
	</div>
	
	<!--dialog-->
	<div id="dd"></div> 
</body>  
<script type="text/javascript">
$(function(){
	dataTable();
	sunDataTable();
});
function dataTable(){
	// 查询页面信息 提交信息
	$('#tt').datagrid(
				{
					title : '父字典',
					toolbar : '#tb',
					url : '../masterCode/queryTopMasterCodes',
					method : 'POST',
					queryParams : {
					},
					striped : true,
					fitColumns : false,
					singleSelect : true,
					rownumbers : true,
					pagination : true,
					nowrap : true,
					striped:true,
				    remoteSort: true,
				    multiSort: true,
					pageSize : 10,
					pageList : [10, 20, 50, 100, 150, 200],
					showFooter : true,
					checkOnSelect :false,
					onRowContextMenu: function(e, rowIndex, rowData){
						e.preventDefault();
						// 显示快捷菜单
						$('#mm').menu('show', {
							left: e.pageX,
							top: e.pageY,
							onClick: function(item){
								if(item.name == 'remove'){
									$.messager.confirm('确认', '您确定要删除系统模块吗？', function(r){
										if (r){
											$.ajax({
												type : "POST",
												url : '../masterCode/deleteMasterCode',
												data : {
													id : rowData.id
												},
												dataType : "json",
												async : false,
												success : function(data) {
													$('#tt').datagrid('reload');
												},
												error : function(e) {
													alert("确认失败！");
												}
											});
										}
									});
								}else if(item.name == 'update'){  
									openDilog(rowData.id);
								}else if(item.name == 'status'){
									$.messager.confirm('确认', '确定变更状态吗？', function(r){
										if (r){
											$.ajax({
												type : "POST",
												url : '../masterCode/updateMasterCodeStatus',
												data : {
													id : rowData.id
												},
												dataType : "json",
												async : false,
												success : function(data) {
													$('#tt').datagrid('reload');
												},
												error : function(e) {
													alert("确认失败！");
												}
											});
										}
									});
								}
							}
						});
					},
					onClickRow: function(rowIndex, rowData){
						sunDataTable(rowData.id,rowData.dicDesc);
					},
					columns : [ [
							/* {field : 'ck', checkbox : true }, */
							{field : 'dicCode',title : '字典编码',	width : 100,align : 'center'},
							{field : 'dicDesc',title : '字典描述',	width : 150,align : 'center'},
							{field : 'remark',title : '备注',	width : 300,align : 'center'},
							{field : 'status',title : '状态',	width : 50,align : 'center',formatter : function(value, row,index) {
								if(row.status == 1){
									return "[生效]";
								}else if(row.status == 0){
									return "失效";
								}else{
									return "异常";
								}
							}}
							] ]
				}).datagrid('resize',{   
			        height:($(window).height()/2-20)   
			    }); 
	}
	
	
function sunDataTable(fatherId,fatherName){
	if(fatherId == undefined || fatherId == null){
		fatherId ='111111111';
		fatherName = "-未选中父菜单！";
	}else{
		$("#fid").val(fatherId);
	}
	// 查询页面信息 提交信息
	$('#tt_sun').datagrid(
				{
					title : '[子字典]'+fatherName,
					toolbar : '#tb_sun',
					url : '../masterCode/querySunMasterCodes',
					method : 'POST',
					queryParams : {
						fatherId : fatherId
					},
					striped : true,
					fitColumns : false,
					singleSelect : true,
					rownumbers : true,
					pagination : true,
					nowrap : true,
					striped:true,
				    remoteSort: true,
				    multiSort: true,
					pageSize : 10,
					pageList : [10, 20, 50, 100, 150, 200],
					showFooter : true,
					checkOnSelect :false,
					onRowContextMenu: function(e, rowIndex, rowData){
						e.preventDefault();
						// 显示快捷菜单
						$('#mm').menu('show', {
							left: e.pageX,
							top: e.pageY,
							onClick: function(item){
								if(item.name == 'remove'){
									$.messager.confirm('确认', '您确定要删除系统模块吗？', function(r){
										if (r){
											$.ajax({
												type : "POST",
												url : '../masterCode/deleteMasterCode',
												data : {
													id : rowData.id
												},
												dataType : "json",
												async : false,
												success : function(data) {
													$('#tt_sun').datagrid('reload');
												},
												error : function(e) {
													alert("确认失败！");
												}
											});
										}
									});
								}else if(item.name == 'update'){  
									openSunDilog(rowData.id);
								}else if(item.name == 'status'){
									$.messager.confirm('确认', '确定变更状态吗？', function(r){
										if (r){
											$.ajax({
												type : "POST",
												url : '../masterCode/updateMasterCodeStatus',
												data : {
													id : rowData.id
												},
												dataType : "json",
												async : false,
												success : function(data) {
													$('#tt_sun').datagrid('reload');
												},
												error : function(e) {
													alert("确认失败！");
												}
											});
										}
									});
								}
							}
						});
					},
					columns : [ [
							/* {field : 'ck', checkbox : true }, */
							{field : 'dicCode',title : '字典编码',	width : 100,align : 'center'},
							{field : 'dicKey',title : '字典Key',	width : 100,align : 'center'},
							{field : 'dicDesc',title : '字典描述',	width : 150,align : 'center'},
							{field : 'remark',title : '备注',	width : 300,align : 'center'},
							{field : 'status',title : '状态',	width : 50,align : 'center',formatter : function(value, row,index) {
								if(row.status == 1){
									return "[生效]";
								}else if(row.status == 0){
									return "失效";
								}else{
									return "异常";
								}
							}}
							] ]
				}).datagrid('resize',{   
			        height:($(window).height()/2-20)   
			    }); 
	}
//新增或更改字典信息
function openDilog(id){
	$('#dd').dialog({    
	    title: '新增或更改',  
	    queryParams : {
	    	id : id
		},
	    width: 400,    
	    height: 200,    
	    closed: false,    
	    cache: false,    
	    href: '../masterCode/createOrUpdateMasterCodePage',    
	    modal: true   
	});
}

function openSunDilog(id){
	var fid = $("#fid").val();
	$('#dd').dialog({    
	    title: '新增或更改子菜单',  
	    queryParams : {
	    	id : id,
	    	fid : fid
		},
	    width: 400,    
	    height: 200,    
	    closed: false,    
	    cache: false,    
	    href: '../masterCode/createOrUpdateSunMasterCodePage',    
	    modal: true   
	});
}
//保存更新菜单信息
function saveOrUpdateMasterCode(url){
	 $.ajax({
		   type:"POST",
		   url:url,
		   data:$('#formBox').serialize(),
		   dataType : "json",
		   async: false,
		   success:function(data){
			   if(data.status){
				   $('#tt').datagrid('reload');
				   $('#dd').dialog('close');
				   $.messager.alert('通知','完成！');
			   }else{
				   $.messager.alert('校验',data.msg[0].defaultMessage);
			   }
		   },
		   error : function(e) {
			   alert("确认失败！");
			}
		  });
}



//保存更新菜单信息
function saveOrUpdateSunMasterCode(url){
	 $.ajax({
		   type:"POST",
		   url:url,
		   data:$('#formBox').serialize(),
		   dataType : "json",
		   async: false,
		   success:function(data){
			   if(data.status){
				   $('#tt_sun').datagrid('reload');
				   $('#dd').dialog('close');
				   $.messager.alert('通知','完成！');
			   }else{
				   $.messager.alert('校验',data.msg[0].defaultMessage);
			   }
		   },
		   error : function(e) {
			   alert("确认失败！");
			}
		  });
}
</script>
</html>